﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <div class="select-list">
                    <ul>
                        <li>
                            角色名称：<input id="roleName" name="RoleName" type="text" />
                        </li>
                        <li>
                            角色状态：<span id="roleStatus" name="RoleStatus"></span>
                        </li>
                        <li class="select-time">
                            <label>创建时间： </label>
                            <input id="startTime" name="StartTime" type="text" class="time-input" placeholder="开始时间" />
                            <span>-</span>
                            <input id="endTime" name="EndTime" type="text" class="time-input" placeholder="结束时间" />
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" >
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" >
                <i class="fa fa-download"></i> 导出
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="gridTable"></table>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {

        $("#roleStatus").ysComboBox({ data: ys.getJson(@Html.Raw(typeof(StatusEnum).EnumToDictionaryString())) });

        var options = {
            id: "gridTable",
            url: "/SystemManage/Role/GetPageListJson",
            createUrl: "/SystemManage/Role/RoleForm",
            updateUrl: "/SystemManage/Role/RoleForm",
            removeUrl: "/SystemManage/Role/DeleteFormJson",
            exportUrl: "",
            modalName: "文章",
            sortName: 'RoleSort',
            sortOrder: 'Asc',
            columns: [
                { checkbox: true, visible: true },
                { field: 'id', title: 'id', visible: false },
                { field: 'roleName', title: '角色名称',sortable: true },
                { field: 'roleSort', title: '显示顺序',sortable: true },
                {
                    field: 'roleStatus', title: '状态',formatter: function (value, row, index) {
		        		return statusTools(row);
		        	}
                },
                {
                    field: 'baseModifyTime', title: '创建时间', formatter: function (value, row, index) {
                        return ys.formatDate(value, "yyyy-MM-dd HH:mm:ss");
                    }
                }
            ],
            onClickRow: function (row, element) {
                element[0].firstElementChild.firstElementChild.click();
            }
        };
        $.table.init(options);
    });
    /* 角色状态显示 */
    function statusTools(row) {
        if (row.roleStatus == 1) {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="changeStatus(\'' + row.id + '\',' + row.roleStatus + ')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="changeStatus(\'' + row.id + '\',' + row.roleStatus +')"></i> ';
        }
    }
    /* 角色管理-停用\启用 */
    function changeStatus(roleId, status) {
        var val = status == 1 ? "停用" : "启用";
        $.modal.confirm("确认要" + val+"角色吗？", function () {
            $.operate.post("/SystemManage/Role/ChangeStatus", { "roleId": roleId});
        })
    }
</script>
